<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商家待打款管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        #guide_ul li{
            margin-top: 5px;
        }
    </style>
</head>
<body>
<div id="aaa"></div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">商家待打款列表</div>
                <div class="layui-card-body">
                    <div class="layui-form-item layui-form">
                       <!--  <div class="layui-inline">
                            <label class="layui-form-label">店铺名称</label>
							
                            <div class="layui-input-block">
                                <input type="text" name="shop_name_"  id="shop_name_"  placeholder="请输入" autocomplete="off" class="layui-input">
                            </div>
                        </div>   -->

                        <div class="layui-inline" >
                            <label class="layui-form-label" >店铺类型：</label>
                            <div class="layui-input-block">
                                <select name="type" id="type">
                                    <option value="0">全部</option>
                                    <option value="1">酒店</option>
                                    <option value="3">旅行社</option>
                                    <option value="2">景点</option> 
                                </select> 
                            </div>
                        </div>
                         <div class="layui-inline">
                          <label class="layui-form-label">结算时间</label>
                          <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="test6" placeholder="  ">
                          </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-btn-group test-table-operate-btn">
                                <button class="layui-btn" data-type="searchUserButton">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                </button>
                            </div>
                        </div>
                        
                    </div>
                    <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate">
                    </table>
                    <script type="text/html" id="test-table-operate-barDemo"> 
                        <a class="layui-btn layui-btn-xs" lay-event="orderlist">查看</a>   
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="contentShow" style="display:none;padding: 30px;">
    <p id="consultation"></p>
</div> 
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
        layui.use('laydate', function(){
  var laydate = layui.laydate;  
  //日期范围
  laydate.render({
    elem: '#test6'
    ,range: true
  }); 
});  
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','table','laydate','set'], function(){
        $ = layui.jquery;
        var table = layui.table
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        table.render({
            elem: '#test-table-operate'
            //,id: 'queryList'
            ,url: "{:url('Settlements/ispayment')}"
            ,height: 'full-100'
            ,cols: [[
                 {field:'settlement_id',width:80,align:'center', title: '结算ID'}
                ,{field:'name',align:'center',title: '店铺名称'} 
                ,{field:'tel', align:'center', title: '联系电话'}
                ,{field:'settlement_money', align:'center', title: '订单总金额'} 
                ,{field:'back_money', align:'center', title: '应结算金额'}  
                ,{field:'commission_fee', align:'center', title: '平台抽成'}
                ,{field:'settlement_type', align:'center', title: '结算类型'}
                ,{field:'settlement_time', align:'center', title: '结算时间'}
                ,{field:'time', align:'center', title: '打款时间'}
                ,{field:'admin_relname', align:'center', title: '操作人员'}
                ,{align:'center',width:350, title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]]
            ,page:true
            ,limit:20
        });

        form.render(null,'component-form-group');

        laydate.render({
            elem: '#search_time'
        });
    var $ = layui.$, active = {
            addadmin: function() {
                window.location.href="{:url('Settlements/orderlist')}";
            },
            searchUserButton:function(){
                var shop_name  = $('#shop_name_').val(); 
                var type  = $('#type').val(); 
                var settlement_time  = $('#test6').val(); 
                table.reload('test-table-operate', {
                    where: { 
                        shop_name:shop_name,
                        type:type,
                        settlement_time:settlement_time
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
                //return false;
            },
            generateSettle:function(){  

                var arr_box = []; 
                var selectData = layui.table.checkStatus('queryList').data;
                var selectlength =selectData.length;
                if(selectlength<=0){
                    layer.msg("请选择要结算的订单");
                    return;
                }
                for(var i=0;i<selectlength;i++){
                     arr_box.push(selectData[i]['settlement_id']);
                } 
                var string = JSON.stringify(arr_box); 

               layer.confirm('共'+selectlength+'笔打款账单，请再次确认', {
                  btn: ['确认','取消'] //按钮
                }, function(){
                    $.ajax({
                url: "{:url('Settlements/doPayments')}",
                type: 'post',
                dataType: 'json',
                data: {data:string},
                success: function(data){  
                    if (data.code === 0) { 
                        layer.msg(data.msg,{icon:2,time:1000});
                    }else if(data.code === 1){ 
                        layer.msg(data.msg,{icon:1,time:1000},function(){window.location.reload();});
                    }else { 
                        layer.msg('结算成功',{icon:2,time:1000});
                    }
                }
             }); 
                }, function(){ 
                    layer.close();
                }); 
            }
        };
        //监听工具条
        table.on('tool(test-table-operate)', function(obj){
            var data = obj.data;
            if(obj.event === 'showDetail'){ 
            }   else if(obj.event === 'orderlist'){
                window.location.href="{:url('Settlements/shoppaymentinfos')}?id=" + data.settlement_id +"&type="+data.object_type;
            }  else if(obj.event === 'dopaymentpage'){
                window.location.href="{:url('Settlements/dopaymentpage')}?id=" + data.settlement_id +"&type="+data.object_type;
            } 
        }); 
        //绑定点击事件
        $('.test-table-operate-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>


</body>
</html>